<template>
  <el-container class="component-map-container" v-if="isMapShow">
    <abbr-map :mapInfo="mapInfo"></abbr-map>
    <div class="input-card">
      <input id="setFitView" type="button" class="btn" value="地图自适应显示" />
    </div>
    <div class="custom-map-tree">
      <el-tree class="tree-detail" :data="treeData" node-key="id" :default-expanded-keys="defaultExdKeys" :props="treeProps"
        :expand-on-click-node="true"
        @node-click="handleNodeClick">
      </el-tree>
    </div>
  </el-container>
</template>
<script>
import AbbrMap from '@/components/AbbrMap'
import {getUserGridTree} from '@/utils/SessionDataUtil'
export default {
  name: 'show-map',
  props: {},
  data () {
    return {
      isMapShow: false,
      mapInfo: null,
      treeData: [],
      treeProps: {
        label: 'name',
        children: 'children'
      }
    }
  },
  components: {
    AbbrMap
  },
  computed: {
    defaultExdKeys: function () {
      if (this.treeData && this.treeData instanceof Array && this.treeData.length > 0) {
        let firstNode = this.treeData[0]
        return [firstNode.id]
      }
    }
  },
  mounted () {
    this.getTreeData()
  },
  methods: {
    // 初始化网格地图
    getTreeData () {
      this.treeData = getUserGridTree()
      this.mapInfo = {
        isPrism: true,
        isAddTextMark: true,
        isLoadPolygon: true,
        viewMode: '3D',
        anchor: 'center',
        polygonInfo: {
          treeData: this.treeData
        },
        textMarkInfo: {
          infoStyle: {
            'opacity': '0.5',
            'background-color': '#ccc',
            'font-size': '14px'
          }
        }
      }
      this.isMapShow = true
    },
    handleNodeClick (data) {
      console.log(data.id)
    }
  }
}
</script>
<style scoped>
.component-map-container {
  position: relative;
  width: 100%;
  height: 100%;
}
.component-map-container .custom-map-tree {
  position: absolute;
  top: 30px;
  left: 30px;
  height: 500px;
  width: 200px;
  overflow-y: scroll;
  overflow-x: hidden;
  z-index: 99999;
}
.component-map-container .custom-map-tree .el-tree{
  padding: 14px 10px;
}
.custom-map-tree::-webkit-scrollbar {
  display: none;
}
.input-card {
  position: absolute;
  bottom: 126px;
  right: 58px;
  z-index: 99999;
}
#setFitView {
  border: none;
  background-color: rgb(206, 212, 212);
  color: black;
  height: 30px;
  line-height: 30px;
  border-radius: 15px;
  padding: 0 10px;
}
</style>
<style>
.content-window-card {
  position: relative;
  box-shadow: none;
  bottom: 0;
  left: 0;
  width: auto;
  padding: 0;
}
.content-window-card p {
  height: 2rem;
}
div.info-middle {
  font-size: 12px;
  padding: 4px 8px;
  line-height: 20px;
}
</style>
